# -*- coding: utf-8 -*-
import datetime
import json
import time
import logging

# pip install requests
import requests

import py_global

logger = logging.getLogger(__name__)


def get():
    http_resp = requests.get("https://www.baidu.com/")
    print(http_resp)
    with open("baidu.html", "wb") as html_file:
        html_file.write(http_resp.content)
        pass
    pass


def get_query():
    url = "http://localhost:5000/"
    params = {
        "keyword": "xxx"
    }
    response = requests.get(url=url, params=params)
    print(response.status_code)
    pass


def post():
    url = "http://localhost:5000/post"
    data_dict = {
        'key': 'value'
    }
    data = json.dumps(data_dict)
    response = requests.post(url=url, data=data, headers={'Content-Type': 'application/json'})
    status_code: int = response.status_code
    content: bytes = response.content
    text: str = response.text
    pass


def post_json():
    url = "http://localhost:5000/post_json"
    data_dict = {
        'key': 'value'
    }
    # application/json
    response = requests.post(url=url, json=data_dict)
    json_dict: dict = response.json()
    value = json_dict.get('key')
    logger.info(f'value:{value}')
    pass


def post_form():
    pass


if __name__ == '__main__':
    # get()
    post()
    # post_json()
    pass
